//
//  MyAppointTwoTableViewCell.m
//  demo
//
//  Created by maxine on 2016/11/11.
//  Copyright © 2016年 maxine. All rights reserved.
//

#import "MyAppointTwoTableViewCell.h"

@interface MyAppointTwoTableViewCell ()<UIPickerViewDataSource,UIPickerViewDelegate>

@property (strong, nonatomic) UIPickerView *rolePickerView;


@end

@implementation MyAppointTwoTableViewCell
+(instancetype)cellWithTableView:(UITableView *)tableView{
    
    //1.创建标识符
    static NSString *ID = @"MAT";
    //2.去缓存池中找
    MyAppointTwoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID ];
    //3.如果找不到就新建
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"MyAppointTwoTableViewCell" owner:nil options:nil] lastObject];
    }
    return cell;
}


- (void)awakeFromNib{
    [super awakeFromNib];
    
    self.produceTf.inputView = self.rolePickerView;
    [self.produceTf reloadInputViews];
}


/**
 懒加载pickerView
 
 @return pickerView
 */
- (UIPickerView *)rolePickerView{
    
    if (!_rolePickerView) {
        _rolePickerView = [[UIPickerView alloc]init];
        _rolePickerView.delegate = self;
        _rolePickerView.dataSource = self;
    }
    return _rolePickerView;
}

//数据源方法
//返回列
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}

//返回行
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return 4;
}

//代理方法
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    
    NSString *str = @"";
    switch (row) {
        case 0:
            str = @"请选择借款用途";
            break;
        case 1:
            str = @"日常生活消费";
            break;
        case 2:
            str = @"经营";
            break;
        case 3:
            str = @"其他";
            break;
        default:
            break;
    }
    return str;
}

//代理方法
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    
    switch (row) {
        case 0:
            self.produceTf.text = @"请选择借款用途";
            break;
        case 1:
            self.produceTf.text = @"日常生活消费";
            break;
        case 2:
            self.produceTf.text = @"经营";
            break;
        case 3:
            self.produceTf.text = @"其他";
            break;
        default:
            break;
    }
}



@end
